// Copyright(c) 2018-2023 Hongjing
// All rights reserved.
//
// Author: Cheng Wang
// Update: 2020-02-05
#ifndef _CAMERA_COMM_H_
#define _CAMERA_COMM_H_
#pragma pack(4)

#include "Platform_Types.h"
#include "rtwtypes.h"



typedef struct {
  /* position_covariance of x */
  real32_T x;

  /* position covariance of y */
  real32_T y;
} J2_Vector2f;

typedef struct {
  real32_T x;
  real32_T y;
  real32_T z;
} J2_Vector3f;

// CAM Sync data
typedef struct {
  uint64 image_time_stamp;
  uint64 spi_time_stamp;
  uint32_T frame_index;
  // 0=Default
  // 1=Fisheye-Back
  // 2=Fisheye-Front
  // 3=Fisheye-Left
  // 4=Fisheye-Right
  // 5=Narrow-Back
  // 6=Narrow-Back-Left
  // 7=Narrow-Left
  // 8=Narrow-Front-Left
  // 9=Narrow-Front
  // 10=Narrow-Front-Right
  // 11=Narrow-Right
  // 12=Narrow-Back-Right
  uint8_T camera_id;
  uint8_T protocol_major_version;
  uint8_T protocol_minor_version;
  uint8_T sw_major_version;
  uint8_T sw_middle_version;
  uint8_T sw_minor_version;
  uint8_T padding[6];
} CAM_Sync;

// CAM AEB data
typedef struct {
  real32_T aeb_brake_decel_req;
  uint8_T protocol_major_version;
  uint8_T protocol_minor_version;
  uint8_T padding_1[2];
  uint32_T fcw_supp_reason;
  uint32_T aeb_supp_reason;
  // 0=NO_SET
  // 1=SET
  uint8_T aeb_latent_warn;
  uint8_T aeb_obj_id_latent_warn;
  // 0=Invalid
  // 1=Car
  // 2=Truck
  // 3=Motors
  // 4=Ped
  // 5=Cyclist
  uint8_T aeb_obj_type_latent_warn;
  uint8_T padding_2;
  real32_T aeb_obj_ttc_latent_warn;
  // 0=NO_SET
  // 1=SET
  uint8_T aeb_pre_warn;
  uint8_T aeb_obj_id_pre_warn;
  // 0=Invalid
  // 1=Car
  // 2=Truck
  // 3=Motors
  // 4=Ped
  // 5=Cyclist
  uint8_T aeb_obj_type_pre_warn;
  uint8_T padding_3;
  real32_T aeb_obj_ttc_pre_warn;
  // 0=NO_SET
  // 1=SET
  uint8_T aeb_prefill;
  uint8_T aeb_obj_id_prefill;
  // 0=Invalid
  // 1=Car
  // 2=Truck
  // 3=Motors
  // 4=Ped
  // 5=Cyclist
  uint8_T aeb_obj_type_prefill;
  uint8_T padding_4;
  real32_T aeb_obj_ttc_prefill;
  // 0=NO_SET
  // 1=SET
  uint8_T aeb_jerk;
  uint8_T aeb_obj_id_jerk;
  // 0=Invalid
  // 1=Car
  // 2=Truck
  // 3=Motors
  // 4=Ped
  // 5=Cyclist
  uint8_T aeb_obj_type_jerk;
  uint8_T padding_5;
  real32_T aeb_obj_ttc_jerk;
  // 0=NO_SET
  // 1=SET
  uint8_T aeb_partial_brake;
  uint8_T aeb_obj_id_partial_brake;
  // 0=Invalid
  // 1=Car
  // 2=Truck
  // 3=Motors
  // 4=Ped
  // 5=Cyclist
  uint8_T aeb_obj_type_partial_brake;
  uint8_T padding_6;
  real32_T aeb_obj_ttc_partial_brake;
  // 0=NO_SET
  // 1=SET
  uint8_T aeb_full_brake;
  uint8_T aeb_obj_id_full_brake;
  // 0=Invalid
  // 1=Car
  // 2=Truck
  // 3=Motors
  // 4=Ped
  // 5=Cyclist
  uint8_T aeb_obj_type_full_brake;
  uint8_T padding_7;
  real32_T aeb_obj_ttc_full_brake;
  // 0=NO_SET
  // 1=SET
  uint8_T aeb_eba;
  uint8_T aeb_obj_id_eba;
  // 0=Invalid
  // 1=Car
  // 2=Truck
  // 3=Motors
  // 4=Ped
  // 5=Cyclist
  uint8_T aeb_obj_type_eba;
  uint8_T padding_8;
  real32_T aeb_obj_ttc_eba;
  // 0=NO_SET
  // 1=SET
  uint8_T aeb_hold;
  uint8_T aeb_obj_id_hold;
  // 0=Invalid
  // 1=Car
  // 2=Truck
  // 3=Motors
  // 4=Ped
  // 5=Cyclist
  uint8_T aeb_obj_type_hold;
  uint8_T padding_9;
  real32_T aeb_obj_ttc_hold;
} CAM_AEBData;

// IHCS object
typedef struct {
  uint8_T obj_id;
  // 0=oncoming
  // 1=couple of oncoming
  // 2=preceding
  // 3=couple of preceding
  // 4=couple of OC upper truck lights
  // 5=stree light
  // 6=strong reflector
  // 7=cluster
  // 15=invalid
  uint8_T obj_type;
  // 0=invalid
  // 1=valid
  boolean_T obj_valid;
  uint8_T obj_releavant_obs_id;
  real32_T coupled_width;
  J2_Vector2f obj_pos;
  real32_T obj_bottom_ang;
  real32_T obj_top_ang;
  real32_T obj_left_ang;
  real32_T obj_right_ang;
} IhcsObj_T;

// Intelligent high-beam control system data
typedef struct {
  // 0=off
  // 1=on
  boolean_T reason_preceding;
  // 0=off
  // 1=on
  boolean_T reason_oncoming;
  // 0=off
  // 1=on
  boolean_T reason_street_light;
  // 0=obviously bright
  // 1=low detection rate
  // 2=in grace
  // 3=deactivated
  // 15=invalid reason
  uint8_T reason_for_ihbc_inactive;
  real32_T environment_lux;
  // 0=High Beam off
  // 1=High Beam on
  boolean_T ihbc_decision;
  // 0=Undecided
  // 1=IHBC_Day
  // 2=IHBC_Inactive
  // 3=IHBC_Full
  uint8_T ihbc_running_mode;
  uint8_T num_of_objects;
  uint8_T protocol_major_version;
  uint8_T protocol_minor_version;
  uint8_T padding[3];
  IhcsObj_T objects[kMaxHrzJ2IHCSObjNum];
} CAM_IhcsData;

// Obstacle Objects
typedef struct {
  uint8_T id;
  // 0=invalid Obstacle(default value)
  // 1=new valid (detected this frame)
  // 2=older valid
  uint8_T valid;
  // 0=not replaced in this frame
  // 1=replaced in this frame
  boolean_T replaced;
  uint8_T confidence;
  // 0=INVALID
  // 1=UNDEFINED
  // 2=PASSING
  // 3=PASSING_IN
  // 4=PASSING_OUT
  // 5=CLOSE_CUT_IN
  // 6=MOVING_IN
  // 7=MOVING_OUT
  // 8=CROSSING
  // 9=LTAP
  // 10=RTAP
  // 11=MOVING
  // 12=PRECEEDING
  // 13=ONCOMING
  uint8_T motion_category;
  // 0=INVALID
  // 1=UNKNOWN
  // 2=MOVING
  // 3=STATIONARY
  // 4=STOPPED
  // 5=MOVING SLOWLY
  uint8_T motion_status;
  // 0=INVALID
  // 1=MEASURED
  // 2=PREDICTED
  uint8_T measuring_status;
  // 0=INVALID
  // 1=VEHICLE
  // 2=PEDESTRIAN
  // 3=CYCLIST
  // 4=GENERAL_OBJECT(reserved)
  uint8_T obstacle_class;
  uint16_T age;

  // 0=Unknown
  // 1=Bus
  // 2=Small_Medium_Car
  // 3=Trucks
  // 4=Motors(Tri-cycle)
  // 5=Special_vehicle
  // 6=Tiny_car
  // 7=Lorry
  uint8_T veh_sub_type;
  // 0=Unknown
  // 1=Adult
  // 2=Child
  uint8_T ped_sub_type;
  // 0=Unknown
  // 1=Bended
  // 2=Cyclist
  // 3=Lier
  // 4=Pedestrian
  // 5=Sitter
  uint8_T ped_pos;
  // 0=Unknown
  // 1=back
  // 2=front
  // 3=left
  // 4=left_front
  // 5=left_back
  // 6=right
  // 7=right_front
  // 8=right_back
  uint8_T ped_orientation;
  // 0=UNKNOWN
  // 1=LEFT_LEFT
  // 2=LEFT
  // 3=HOST
  // 4=RIGHT
  // 5=RIGHT_RIGHT
  uint8_T lane_assignment;
  // 0=Default
  // 1=Obstacle not occluded
  // 2=Obstacle occluded
  uint8_T occluded;
  // 0=not CIPV
  // 1=CIPV
  boolean_T cipv_flag;
  // 0=not MCP
  // 1=MCP
  boolean_T mcp_flag;
  // 0=Unavailable
  // 1=Off
  // 2=Left
  // 3=Right
  // 4=Both
  uint8_T blinker_info;
  // 0=OFF
  // 1=ON
  boolean_T brake_lights;
  // 0=Unknown
  // 1=RearLeft
  // 2=RearCenter
  // 3=RearRight
  // 4=FrontLeft
  // 5=FrontCenter
  // 6=FrontRight
  // 7=LeftCenter
  // 8=RightCenter
  // 9=Center
  uint8_T position_type;
  uint8_T tracking_confidence;
  // 0=not cut in
  // 1=cut in
  // 2=close cut in
  uint8_T cut_in_flag;
  uint8_T padding1;
  real32_T length;
  real32_T width;
  real32_T height;
  real32_T center_angle;
  real32_T obstacle_ttc;
  uint8_T padding2[4];
  J2_Vector2f pos_rel;
  J2_Vector2f velocity_rel;
  J2_Vector2f acceleration_rel;
  J2_Vector2f position_rel_sd;
  J2_Vector2f velocity_rel_sd;
  real32_T obstacle_angle;
  real32_T angle_std;
  J2_Vector2f velocity_rel_abs;
  J2_Vector2f corner_point_pox;
  real32_T cut_in_distance;
  real32_T curvature_radius;
} ObstacleObj_T;

// Obstacle
typedef struct {
  uint8_T num_obstacles;
  uint8_T protocol_major_version;
  uint8_T protocol_minor_version;
  uint8_T id_cipv;
  uint8_T id_mcp;
  boolean_T cipv_ttc_valid;
  boolean_T mcp_ttc_valid;
  boolean_T cipv_hwm_valid;
  real32_T cipv_ttc;
  real32_T mcp_ttc;
  real32_T cipv_hwm;
  uint8_T padding[4];
  ObstacleObj_T objects[kMaxHrzJ2ObstacleNum];
  uint32_T internal_id[kMaxHrzJ2ObstacleNum];
} CAM_Obstacle;

// Lane marker
typedef struct {
  uint16_T track_id;
  uint8_T confidence;
  // 0=Unknown
  // 1=New
  // 2=Measured_Parallel
  // 3=Predicted_Parallel
  // 4=Measured_Unparallel
  // 5=Predicted_Unparallel
  // 6=Not valid
  uint8_T measuring_status;
  // 0=Unknown
  // 1=Solid
  // 2=Road Edge
  // 3=Dashed
  // 4=Double Lane(Left Dashed, Right Solid)
  // 5=Double Lane(Left Solid, Right Dashed)
  // 6=Double Lane(Double Dashed)
  // 7=Double Lane(Double Solid)
  // 8=Reserved
  // 9=Line Ramp
  // 15=Invalid
  uint8_T type_class;
  // 0=Unknown
  // 1=White
  // 2=Yellow_Orange_Red
  // 3=Blue_Green
  uint8_T mark_color;
  // 0=Unknown
  // 1=Low quality
  // 2=High quality
  // 3=Very High quality
  uint8_T quality;
  // 0=FALSE
  // 1=TRUE
  uint8_T crossing;
  real32_T width_marking;
  real32_T view_range_start;
  real32_T view_range_end;
  real32_T model_c0;
  real32_T model_c1;
  real32_T model_c2;
  real32_T model_c3;
  real32_T tlc;
  // 0=Lanemark no Obstacle
  // 1=Lanemark Obstacle Left
  // 2=Lanemark Obstacle Right
  // 3=Lanemark Obstacle Both
  uint8_T obstacle_flag;
  // 0=Default
  // 1=Division
  // 2=Merge
  // 3=Highway Exit Start
  // 4=Highway Exit End
  uint8_T extra_near_point_type;
  // 0=Default
  // 1=Division
  // 2=Merge
  // 3=Highway Exit Start
  // 4=Highway Exit End
  uint8_T extra_far_point_type;
  uint8_T parsing_confidence;
  boolean_T stop_line_relevancy;
  uint8_T padding[3];
  J2_Vector2f extra_far_point_pos;
  J2_Vector2f extra_near_point_pos;
} LineMsg_T;

// Cone Road Edge
typedef struct {
  uint16_T track_id;
  uint8_T confidence;
  // 0=Unknown
  // 1=New
  // 2=Measured_Parallel
  // 3=Predicted_Parallel
  // 4=Measured_Unparallel
  // 5=Predicted_Unparallel
  // 6=Not valid
  uint8_T measuring_status;
  // 0=Default
  // 1=Traffic Cone
  // 2=Other Cone
  uint8_T type_class;
  //   0=Unknown
  // 1=Low quality
  // 2=High quality
  // 3=Very High quality
  uint8_T quality;
  uint8_T parsing_confidence;
  uint8_T padding_1;
  real_T view_range_start;
  real_T view_range_end;
  real32_T model_c0;
  real32_T model_c1;
  real32_T model_c2;
  real32_T model_c3;
  real32_T tlc;
  uint8_T padding_2[4];
} ConeRoadEdge_T;

// Lane marker
typedef struct {
  real32_T host_etimated_width;
  real32_T dis_stop_line;
  // 0=Unknown
  // 1=Highway
  // 2=Urban
  // 3=Rural
  // 4=Tunnel
  // 5=Other
  uint8_T road_type;
  // 0=Unknown
  // 1=Sunny
  // 2=Cloudy
  // 3=Rainy
  // 4=Snowy
  // 5=HeavyRainy
  // 6=Foggy
  // 7=Other
  uint8_T current_weather;
  // 0=Unknown
  // 1=Day
  // 2=Night
  // 3=Other
  uint8_T current_time;
  // 0=Unknown
  // 1=Naturallight
  // 2=Lamplight
  // 3=Hardlight
  // 4=Lowsun
  // 5=Dark
  // 6=Other
  uint8_T light_type;
  // 0=Invalid
  // 1=Valid
  boolean_T dis_stop_line_valid;
  uint8_T protocol_major_version;
  uint8_T protocol_minor_version;
  uint8_T padding;
  LineMsg_T line_msg[kMaxHrzJ2LaneMarkerNum];
  ConeRoadEdge_T cone_road_edge_msg[kMaxHrzJ2ConeRoadEdgeNum];
} CAM_LaneMarker;

// Traffic light message
typedef struct {
  uint8_T id;
  uint8_T confidence;
  // 0=Unknown
  // 1=Red
  // 2=Green
  // 3=Yellow
  // 4=Other
  // 5=Off
  uint8_T color;
  // 0=Unknown/Unsupported
  // 1=Vertical 3-light
  // 2=Horizontal 3-light
  uint8_T shape_type;
  // 0=Unknown
  // 1=L_Circle
  // 2=L_Forward
  // 3=L_Left
  // 4=L_Right
  // 5=L_Return
  // 6=L_Pedestrian
  // 7=L_Non_Motor
  // 8=L_Time
  // 9=L_Other (Reserved)
  // 10=L_left_and_return
  // 11=L_Forward_and_Left
  // 12=L_Forward_and_Right
  // 13=L_No_Drive_into
  // 14=L_Allow_Drive_into
  // 15=text_of_allow_ped (Reserved)
  // 16=sign_of_allow_ped (Reserved)
  // 17=text_of_forbid_ped (Reserved)
  // 18=sign_of_forbid_ped (Reserved)
  uint8_T classification_type;
  // 0=No_Blinking
  // 1=Blinking
  boolean_T blinking;
  uint8_T padding[2];
  J2_Vector3f position_rel;
  real32_T width;
} CAM_TFL_MSG;

// Traffic light
typedef struct {
  uint8_T objects_num;
  uint8_T main_object_id;
  uint8_T protocol_major_version;
  uint8_T protocol_minor_version;
  uint8_T padding[4];
  uint32_T internal_id[kMaxHrzJ2TFLNum];
  CAM_TFL_MSG tfl_msg[kMaxHrzJ2TFLNum];
} CAM_TFL;

// Traffic sign message
typedef struct {
  uint8_T id;
  uint8_T confidence;
  uint8_T road_mark_type;
  // 0=Undefined
  // 1=IN_HOSTLANE_SIGN
  // 2=NOT_IN_HOSTLANE
  // 3=HIGHWAY_EXIT_SIGN (Reserved)
  // 4=SIGN_ON_TURN (Reserved)
  // 5=FAR_IRRELEVANT_SIGN (Reserved)
  // 6=TSR_RAMP_RELEVANT
  uint8_T relevancy;
  uint16_T traffic_sign_type;
  // 0=Not filtered
  // 1=Irrelevant to the host driver
  // 2=On vehicle/truck
  // 3=Embedded(Reserved)
  // 4=RESERVED
  // 5=RESERVED
  // 6=RESERVED
  // 7=RESERVED
  uint8_T filter_type;
  // 0=Not Approved
  // 1=Approved
  uint8_T approved_flag;
  J2_Vector3f position_rel;
  uint8_T padding[4];
} CAM_TSR_MSG;

// Traffic sign
typedef struct {
  uint8_T objects_num;
  uint8_T protocol_major_version;
  uint8_T protocol_minor_version;
  uint8_T padding[5];
  uint32_T internal_id[kMaxHrzJ2TSRNum];
  CAM_TSR_MSG tsr_msg[kMaxHrzJ2TSRNum];
} CAM_TSR;

// Free space
typedef struct {
  uint8_T protocol_major_ver;
  uint8_T protocol_minor_ver;
  uint8_T padding[6];
  J2_Vector2f position_rel[kMaxHrzJ2FSPointNum];
  // 0=ignore
  // 1=car
  // 2=road delimiter
  // 3=pedestrain
  // 4=reserved
  // 5=reserved
  // 6=reserved
  // 7=reserved
  uint8_T type[kMaxHrzJ2FSPointNum];
} CAM_FreeSpace;

// Fail Safe
typedef struct {
  uint8_T protocol_major_ver;
  uint8_T protocol_minor_ver;
  // 0=false
  // 1=true
  boolean_T acc_blind_dcsn;
  // 0=false
  // 1=true
  boolean_T tsr_blind_dcsn;
  // 0=false
  // 1=true
  boolean_T hlb_blind_dcsn;
  // 0=false
  // 1=true
  boolean_T ped_blind_dcsn;
  // 0=false
  // 1=true
  boolean_T ld_blind_dcsn;
  // 0=false
  // 1=true
  boolean_T vd_blind_dcsn;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T impaired_vd;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T low_sun;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T blur_image;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T smeared_image;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T partial_transparent_blockage;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T full_blockage_bits;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T splashes;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T out_of_cal;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T cal_misalignment;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T smeared_spots;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T freeze_windshield;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T foggy_spots;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T sun_ray;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 7=unknown
  uint8_T self_glare;
  // 0=none
  // 1=low
  // 2=medium
  // 3=high
  // 8=unknown
  uint8_T fs_freeze;
  uint8_T padding;
} CAM_FailSafe;

// Calibration
typedef struct {
  // 0=Init
  // 1=Normal
  // 2=After-Run
  // 3=Stop
  // 4=Onl-Calibration
  // 5=Onl-Calibrating-Finish
  // 6=Eol-Calibration
  // 7=Eol-Calibration-Finish
  // 8=OTA-prepare
  // 9=OTA
  // 10=System-Fault
  // 11=Reserved
  // 12=Reserved
  uint8_T rt_sys_sts;
  // 0=Unknown
  // 1=Camera Calibrated
  // 2=Intrinsics Default
  // 3=Extrinsics Default
  // 4=Camera no Calibrated
  uint8_T cam_cal_sts;
  // 0=Default
  // 1=Fisheye-Back
  // 2=Fisheye-Front
  // 3=Fisheye-Left
  // 4=Fisheye-Right
  // 5=Narrow-Back
  // 6=Narrow-Back-Left
  // 7=Narrow-Left
  // 8=Narrow-Front-Left
  // 9=Narrow-Front
  // 10=Narrow-Front-Right
  // 11=Narrow-Right
  // 12=Narrow-Back-Right
  uint8_T cam_id;
  uint8_T padding_1;
  uint32_T frame_idx;
  // aocp means AutoOnlineCalibrationParam
  real_T aocp_pitch;
  real_T aocp_yaw;
  real_T aocp_roll;
  // ac means AutoCalibration
  // 0=Function Disable
  // 1=Function Enable
  boolean_T ac_enabled;
  boolean_T ac_sts_pitch;
  boolean_T ac_sts_yaw;
  boolean_T ac_sts_roll;
  boolean_T ac_out_of_range_pitch;
  boolean_T ac_out_of_range_yaw;
  boolean_T ac_out_of_range_roll;
  boolean_T ac_success;
  uint8_T ac_progress;
  uint8_T padding[3];
} CAM_Calibration;


#pragma pack()
#endif  // AUTODRIVE_SENSOR_ADAPTER_SENSOR_CAMERA_MOBILEYE_MOBILEYE_COMM_H_
